/**
 * Created by thinkl on 2017/7/4.
 */
$(function () {
    var app_data = {
        commodity_imgs: []
    };
    var app = new Vue({
        el: '#commodity_img',
        data: app_data,
        methods: {
            delete_img: function (img_id) {
                $.post('/commodity/delete_img', {img_id: img_id}, function (data) {
                    var obj = JSON.parse(data);
                    if (obj.success) {
                        location.reload()
                    }
                })
            }
        }
    });
    var goods_id = getQueryString('id');
    $.post('/commodity/get_commodity', {commodity_id: goods_id}, function (data) {
        var obj = JSON.parse(data);
        app_data.commodity_imgs = obj.result.li;

    })

});

function img_save() {
    var goods_id = getQueryString('id');
    var formData = new FormData();
    formData.append("img", $("#upload")[0].files[0]);
    formData.append("goods_id", goods_id);
    $.ajax({
        url: '/commodity/create_imgs',
        type: 'POST',
        data: formData,
// 告诉jQuery不要去处理发送的数据
        processData: false,
// 告诉jQuery不要去设置Content-Type请求头
        contentType: false,
        beforeSend: function () {
            console.log("正在进行，请稍候");
        },
        success: function (responseStr) {
            var l = JSON.parse(responseStr);
            if (l) {
                console.log("成功" + l.message);
                location.reload()
            } else {
                console.log("失败");
            }
        },
        error: function (responseStr) {
            console.log("error");
        }
    });
}
